package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description: 测试类
 * User: mac
 * Date: 2022-09-06
 * Time: 15:52
 */
class Shape {
    public void draw() {

    }
}

class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("♦");
    }
}

class Flower extends Shape{
    @Override
    public void draw(){
        System.out.println("❀");
    }
}

class Triangle extends Shape{
    @Override
    public void draw(){
        System.out.println("△");
    }
}

class Clyle extends Shape {
    @Override
    public void draw(){
        System.out.println("●");
    }
}
public class Test {
    //多态 - 昌盛
    public static void main(String[] args) {
        Rect rect = new Rect();
        Flower flower = new Flower();
        Triangle triangle = new Triangle();
        
        Shape[] shapes = {rect,flower,triangle,new Clyle()};
        for (Shape shape:
             shapes) {
            shape.draw();
        }
    }
    //if - else - 挫
    public static void main3(String[] args) {
        Rect rect = new Rect();
        Flower flower = new Flower();
        Triangle triangle = new Triangle();

        String[] shapes = {"triangle", "rect", "flower"};
        for (String s:
             shapes) {
            if (s.equals("triangle")){
                triangle.draw();
            } else if (s.equals("rect")){
                rect.draw();
            } else {
                flower.draw();
            }
        }
    }

    //多态 - 通过此处的同一个引用调用同一个方法，呈现出了不同的形态
    public static void drawMap(Shape shape) {
        shape.draw();
    }

    public static void main2(String[] args) {
        drawMap(new Rect());
        drawMap(new Flower());
        drawMap(new Triangle());
    }
    public static void main1(String[] args) {
        Shape shape1 = new Rect();
        shape1.draw();
        Shape shape2 = new Flower();
        shape2.draw();
    }
}
